<?php
	require_once("../../include_dao.php");
		
	if(	$_POST['name']  != ''  and $_POST['stakeholders']  != '' and $_POST['director'] != '' and 
		$_POST['format'] != '' and $_POST['year'] != '' and 
		$_POST['rate'] != '' and $_POST['price'] != '' and 
		$_POST['priceRentals'] != '' and $_POST['languages'] != '' and $_POST['subtitles'] != '' and $_POST['description'] != '' 			and  $_POST['runtime'] != '' and  $_POST['picturePath'] != '' ){
			
		
		$name = $_POST['name'];
		$stakeholders= $_POST['stakeholders'];
		$director = $_POST['director'];
		$format = $_POST['format'];
		$year = $_POST['year'];
		$rate = $_POST['rate'];
		$price = $_POST['price'];
		$priceRentals = $_POST['priceRentals'];
		$languages = $_POST['languages'];
		$subtitles = $_POST['subtitles'];
		$description = $_POST['description'];
		$runtime = $_POST['runtime'];
		$pKMovie= $_POST['PkMovie'];
	$fKGender= $_POST['fKGender'];
	$picturePath= $_POST['picturePath'];

			// Inicia la Trasaccionalidad para hacer ingresos de informacion
			$transaction = new Transaction();			
			try{
					
				// Preparo para Guardar informacion 
				$dtomovie = new Movie();	
				$dtomovie->pKMovie = $pKMovie;	
				$dtomovie->name =  $name;					
				$dtomovie->stakeholders = $stakeholders;			
				$dtomovie->director = $director;			
				
				$dtomovie->fKGender= $fKGender;	
				$dtomovie->active = 1;
				$dtomovie->visible = 1;			
				$dtomovie->format = $format;			
				$dtomovie->year = $year;			
				$dtomovie->rate = $rate;				
				$dtomovie->price = $price;	
				$dtomovie->runtime = $runtime;
				$dtomovie->priceRentals =  $priceRentals;					
				$dtomovie->languages = $languages;			
				$dtomovie->subtitles = $subtitles;			
				$dtomovie->description = $description;	
				$dtomovie->picturePath = "./img/p_movie/". $picturePath;	
			
				/// Guarda La informacion 
				print_r($dtomovie);	
				if($pKMovie== 0)
					DAOFactory::getMovieDAO()->insert($dtomovie);
				else 
					DAOFactory::getMovieDAO()->update($dtomovie);
					
			
				
				//commit transaction
				$transaction->commit();
				
				// Redirecciono a la pantalla principal 
				header( 'Location: ../../movies_list.php?err=40');
			}catch (Exception $e){	
			
			//	// Anulo la Transaccion
				$transaction->rollback();			
				header( 'Location: ../../movies_list.php?err=31');
			}	
		
		
		}else{
		header( 'Location: ../../movies_list.php?err=13');
		}
?>